<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/WEB-INF/common/taglibs.jsp" %>
<%@ taglib prefix="fmt" uri="http://java.sun.com/jsp/jstl/fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Insert title here</title>
<link rel="stylesheet" href="${ctx}/static/lib/layui/css/layui.css">
</head>
<body>
	<fmt:formatDate value="${planData}" pattern="yyyy-MM-dd"/>
	<div class="demoTable">
		<button class="layui-btn" data-type="success">
			开发完成
		</button>
		<button class="layui-btn" data-type="fail">
			开发失败
		</button>
		<!--这里写一个下拉框 区分状态  -->
		
		
		<button class="layui-btn" data-type="add">
			添加
		</button>
		<!--隐藏标签 存放id  -->
		<!--传值成功  -->
		<input type="hidden" name="saleId"  value="${saleChanceId}"/>
	</div>

	<table id="tableId" class="layui-hide" lay-filter="tableFilter"></table>
	<!--  <script type="text/html" id="barDemo">
     <a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="detail">开发</a>
     <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
     <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
   </script>-->
   
   	<!--把销售机会从 数字 转换成 汉字-->
	<!--  <script type="text/html" id="saleChanceIdTpl">
		{{# if(d.saleChanceId == 1){       }}
				网络销售
		{{# }else if(d.saleChanceId == 2){ }}
				电视广告
		{{# }else {                        }}
				电话
		{{# }                  }}
	</script>-->
	<script src="${ctx}/static/back/js/jquery.min.js?v=2.1.4"></script>
	<script src="${ctx}/static/common/mylayer.js"></script>
	<script src="${ctx}/static/common/util.js"></script>
	<script src="${ctx}/static/lib/layui/layui.js"></script>
	<script>
		layui.use('table', function() {
			var table = layui.table;
			table.render({
			    elem: '#tableId'
			    ,url: '${ctx}/cusdevplan/getCusDevPlanPageList.action?id=${param.id}'//数据接口
			    ,page: true //开启分页
			    ,id :"layUITableId"
			    ,cols: [[ //表头
			        //复选框
			      {type:'checkbox',fixed:'left'}
			    	//以下是表格内容
			      ,{field: 'id', title: '编号', width:80, sort: true, fixed: 'left'}
			      ,{field: 'saleChanceId', title: '销售机会', width:130, sort: true, templet:"#saleChanceIdTpl"}
			      ,{field: 'planItem', title: '计划项', width:120} 
			      ,{field: 'planDate', title: '计划日期', width: 170,templet: "<span>{{layui.util.toDateString(d.planDate, 'yyyy-MM-dd ')}}</span>"}
			      ,{field: 'exeAffect', title: '执行效果', width: 170, sort: true}
			      ,{field: 'createTime', title: '创建时间', width: 135, sort: true}
			      ,{field: 'updateTime', title: '更新时间', width: 135, sort: true}
			    ]]
			  });
			
		  //监听工具条
		  //tool是工具条事件名，tableFilter是table容器属性lay-filter="tableFilter"对应的值
		  table.on('tool(tableFilter)', function(obj){
		    var data = obj.data;//获得当前行数据,json格式对象
		    var layEvent = obj.event;//获得lay-event对应的值
		    if(layEvent === 'detail'){
		    	location.href = "${ctx}/salechance/getCusdevplanPage.action";
		      //layer.msg('ID：'+ data.id + ' 的查看操作');
		    } else if(layEvent === 'del'){
		    	/*根据ID删除，通过ajax方式提交  */
		      layer.confirm('真的删除本行么', function(index){
		    	$.ajax({
		    		url:"${ctx}/user/deleteById.action",
		    		data:{"id":data.id},
		    		dataType:"json",
		    		success:function(resp) {
		    			if(resp.code == util.SUCCESS){
		    				mylayer.success(resp.msg);
		    				table.reload("layUITableId");
		    			} else {
		    				mylayer.errorMsg(resp.msg);
		    			}
			        layer.close(index);
		    		}
		    	});
		      });
		    } else if(obj.event === 'edit'){
		      layer.alert('编辑行：<br>'+ JSON.stringify(data))
		    }
		  });
		  
		var active = {
				//开发完成
				success : function() {
					var saleChanceId = ${param.id};
					alert(saleChanceId);
					//获取全部信息，添加到订单界面，然后跳转到订单界面
					$.ajax({
						url:"${ctx}/order/insert.action",
						data:{"id":saleChanceId},
						type:"post",
						dataType:"json",
						success :function (resp) {
							if (resp.code == util.SUCCESS) {
								mylayer.confirm("添加成功，点击跳转到订单界面","${ctx}/order/getPage.action");
							}
						}
					});
					
				},
				
				//添加
				add : function() {
					var index = layer.open({
			    		  type: 2,
			    		  content: '${ctx}/cusdevplan/add.action?saleChanceId=${param.saleChanceId}',
			    		  area: ['500px', '350px'],
			    		});
			    		//layer.full(index);
					//location.href = "${ctx}/cusdevplan/add.action";
				}
		}
		
		$('.demoTable .layui-btn').on('click',function(){
			var type=$(this).data('type');
			active[type]?active[type].call(this):'';
		});
	});
	</script>
</body>
</html>